home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / oscar / Snactivator.pyo (.txt) < prev   
Python Compiled Bytecode  |  2008-10-13  |  3KB  |  93 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from __future__ import with_statement
  5. from itertools import count
  6. from traceback import print_exc
  7. from util import TimeOut, PriorityQueue, EmptyQueue
  8. import logging
  9. log = logging.getLogger('oscar.snactivator')
  10.  
  11. class Snactivator(TimeOut):
  12.     ids = count()
  13.     
  14.     def __init__(self, socket):
  15.         TimeOut.__init__(self)
  16.         self.socket = socket
  17.         self.queues = [ PriorityQueue() for __ in xrange(len(socket.rate_classes)) ]
  18.  
  19.     
  20.     def send_snac(self, snac, priority = 5):
  21.         if self.finished():
  22.             log.error("Snactivator can't send this snace, because it's finished: %r", snac)
  23.             return None
  24.         
  25.         rclass = self.socket.snac_rate_class(*snac)
  26.         if not rclass:
  27.             return self.socket._send_snac(snac)
  28.         
  29.         self._cv.__enter__()
  30.         
  31.         try:
  32.             queue = self.queues[self.socket.rate_classes.index(rclass)]
  33.             queue.append(snac, priority)
  34.             self._cv.notify()
  35.         finally:
  36.             pass
  37.  
  38.  
  39.     
  40.     def compute_timeout(self):
  41.         if self.finished():
  42.             self._last_computed = -1
  43.             self.socket = None
  44.         else:
  45.             times = []
  46.             for q in (lambda .0: for queue in .0:
  47. if queue:
  48. queuecontinue)(self.queues):
  49.                 snac = q.peek()
  50.                 t = self.socket.time_to_send(snac)
  51.                 times.append(t)
  52.             
  53.             if not times:
  54.                 pass
  55.             self._last_computed = min([
  56.                 5])
  57.         return self._last_computed
  58.  
  59.     
  60.     def process(self):
  61.         for q in self.queues:
  62.             if not q:
  63.                 continue
  64.             
  65.             
  66.             try:
  67.                 snac = q.peek()
  68.             except EmptyQueue:
  69.                 continue
  70.  
  71.             t = self.socket.time_to_send(snac)
  72.             if t == 0 and not self.finished():
  73.                 
  74.                 try:
  75.                     snac = q.next()
  76.                 except Exception:
  77.                     return None
  78.  
  79.                 
  80.                 try:
  81.                     self.socket._send_snac(snac)
  82.                 except Exception:
  83.                     print_exc()
  84.                     self.socket.test_connection()
  85.                 except:
  86.                     None<EXCEPTION MATCH>Exception
  87.                 
  88.  
  89.             None<EXCEPTION MATCH>Exception
  90.         
  91.  
  92.  
  93.